//
//  ZSBaseViewController.m
//  Timy
//
//  Created by zsj1992 on 16/12/12.
//  Copyright © 2016年 bjhj. All rights reserved.
//

#import "ZSBaseViewController.h"
#import <MMDrawerController.h>
#import "AppDelegate.h"
#import "UIBarButtonItem+Extension.h"
#import "ZSItemCell.h"
#import "ZSCustomButton.h"

#import "LYPopTransition.h"
#import "LYPushTransition.h"

#import "ZSEditViewController.h"


@interface ZSBaseViewController ()<UITableViewDelegate,UITableViewDataSource,UIViewControllerTransitioningDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet ZSCustomButton *btnAdd;

@end

@implementation ZSBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIBarButtonItem * itemL = [UIBarButtonItem creatItemWithImageName:@"btn_menu" selectedImage:@"" andTarget:self action:@selector(callOfLeft) title:nil];
    UIBarButtonItem * itemR = [UIBarButtonItem creatItemWithImageName:@"btn_bulb_push" selectedImage:@"" andTarget:self action:@selector(callOfRight) title:nil];

    self.navigationItem.leftBarButtonItem = itemL;
    self.navigationItem.rightBarButtonItem = itemR;
    
    //设置导航栏全透明
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];

}




-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 20;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    ZSItemCell * cell = [ZSItemCell cellWithTableView:tableView];
    
    cell.textLabel.text = @"sss";
    
    return cell;
    
}

BOOL add;

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    CGFloat offsetY = scrollView.contentOffset.y;

    self.btnAdd.transform = CGAffineTransformMakeRotation(-offsetY/32);
    
    
    if (offsetY<-120) {
        add = YES;
    }
    
    
    
}

//减速完成
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    if (add) {//在这里面添加那个选择的界面
        
        NSLog(@"下拉");
        
        ZSEditViewController * editVc = [[ZSEditViewController alloc]init];
        
        
        editVc.transitioningDelegate = self;
        
        
        [self presentViewController:editVc animated:YES completion:nil];
        
        
        
        add = NO;
        
    }
    if (scrollView.contentOffset.y>0) {
        
        self.btnAdd.transform = CGAffineTransformMakeRotation(0);
        
    }

    
}







-(void)callOfLeft{
    
    AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [appDelegate.mmDrawerManager openDrawerSide:(MMDrawerSideLeft) animated:YES completion:nil];
}


-(void)callOfRight{
    AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [appDelegate.mmDrawerManager openDrawerSide:(MMDrawerSideLeft) animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)close:(id)sender {
    
}



-(id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{

    return [LYPushTransition new];


}

-(id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{

    return [LYPopTransition new];
}










@end
